//
//  PregnancyKwoledgeViewController.m
//  hospitalVIP
//
//  Created by xiaoyan on 14-1-7.
//  Copyright (c) 2014年 MEETStudio. All rights reserved.
//

#import "PregnancyKwoledgeViewController.h"

@interface PregnancyKwoledgeViewController ()
{
    ASIHTTPConnection *weekTips_connect;
    NSArray *categes;
}
@end

@implementation PregnancyKwoledgeViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc{
    
    if (weekTips_connect != nil) {
        weekTips_connect.connectionDelegate = nil;
        [weekTips_connect release];
        weekTips_connect = nil;
    }
    
   
    
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bg_pattern_wood" ofType:@"png"];
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]];
    
    
    [self setTItleWith:@"孕周知识"];
    
    
    //ios7 优化
    
    if( iOS7) {
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.navigationBar.translucent = NO;
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
        
    }
    else{
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
    }
    
    
    UIButton *leftBt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [leftBt setImage:[UIImage imageNamed:@"icon_return.png"] forState:UIControlStateNormal];
    [leftBt addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:leftBt];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    [leftBt release];
    [leftButton release];
    
    
    //
    NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"testicon2.jpg",@"picurl",@"温馨提示",@"name", nil];
    NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"testicon3.jpg",@"picurl",@"饮食与营养",@"name", nil];
    NSDictionary *dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"testicon4.jpg",@"picurl",@"宝宝的发育",@"name", nil];
    NSDictionary *dict4 = [NSDictionary dictionaryWithObjectsAndKeys:@"testicon5.jpg",@"picurl",@"你的变化",@"name", nil];
    
    categes = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,dict4, nil];

    
}

- (void)loadData{
    
    
    NSString *urlString = [NSString stringWithFormat:@"http://211.83.105.71:3306/MonitorSystem_V1.0/Mobile/week_weekknowledge?weekid=%d",1];
	NSURL *url = [NSURL URLWithString:urlString];
    
    if (weekTips_connect != nil) {
        weekTips_connect.connectionDelegate = nil;
        [weekTips_connect release];
        weekTips_connect = nil;
    }

    
    weekTips_connect = [[ASIHTTPConnection alloc] initGETWithURL:url resultDict:YES isCache:YES];
    weekTips_connect.connectionDelegate = self;
    
    [weekTips_connect startAsynchronous];

}

- (void)backAction:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setTItleWith:(NSString *)title{
    
    UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if (!titleView) {
        titleView = [[UILabel alloc] initWithFrame:CGRectZero];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont systemFontOfSize:20.0];
        
        titleView.textColor = [UIColor whiteColor]; // Change to desired color
        
        self.navigationItem.titleView = titleView;
        [titleView release];
    }
    titleView.text = title;
    [titleView sizeToFit];
    
    
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 40;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.backgroundColor = [UIColor clearColor];
        
            UIImageView *bgview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 300,90 )];
            bgview.backgroundColor = [UIColor colorWithRed:192/255.0 green:174/255.0 blue:151/255.0 alpha:1];
            [cell.contentView addSubview:bgview];
            bgview.clipsToBounds = YES;
            [bgview release];
            
            UIImageView *signImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 80, 80)];
            signImageView.image = [UIImage imageNamed:@"testicon2.png"];
            signImageView.tag = 7;
            signImageView.clipsToBounds = YES;
            [signImageView setContentMode:UIViewContentModeScaleAspectFill];
            [cell.contentView addSubview:signImageView];
            [signImageView release];
            
            UILabel *nameLable = [[UILabel alloc] initWithFrame:CGRectMake(105, 10, 220, 40)];
            nameLable.tag = 8;
            nameLable.textColor = [UIColor colorWithRed:51.0 / 255.0 green:26.0 / 255.0 blue:3.0 / 255.0 alpha:1.0];
            nameLable.font = [UIFont boldSystemFontOfSize:17];
            nameLable.textAlignment = NSTextAlignmentLeft;
            nameLable.text = @"";
            [cell.contentView addSubview:nameLable];
            [nameLable release];
            
            
        
            
            UILabel *sublable1 = [[UILabel alloc]initWithFrame:CGRectMake(105, 40, 200, 52)];
            sublable1.font = [UIFont systemFontOfSize:12];
           sublable1.numberOfLines = 3;
             sublable1.textColor = [UIColor blackColor];
            sublable1.backgroundColor = [UIColor clearColor];
            [cell.contentView addSubview:sublable1];
            sublable1.text = @"孕妇可以通过上面的提示填写自身的状态，心情，饮食，以及运动情况，进而呢通过软件推荐孕妇如何去做。然后上面设定去做孕检的时间，检查项目，里面设定各阶段的检查项目结果分析，可以作为自己身体状况的一个参考";
            [sublable1 release];
            
        
            
    }
    
   
        UIImageView *imageView = (UIImageView*)[cell.contentView viewWithTag:7];
        NSString *imagename = [[categes objectAtIndex:indexPath.row] objectForKey:@"picurl"];
        imageView.image = [UIImage imageNamed:imagename];
        
        
        UILabel *namelable = (UILabel*)[cell.contentView viewWithTag:8];
        NSString *name = [[categes objectAtIndex:indexPath.row] objectForKey:@"name"];
        namelable.text = name;
 
    // Configure the cell...
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 3) {
        return 110;
    }
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WeekDetailViewController *con = [[WeekDetailViewController alloc]init];
    [self.navigationController pushViewController:con animated:YES];
    [con release];
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 25)];
    lable.text = [NSString stringWithFormat:@" 孕%d周",section];
    lable.font = [UIFont systemFontOfSize:14];
    lable.textColor = [UIColor colorWithRed:51.0 / 255.0 green:26.0 / 255.0 blue:3.0 / 255.0 alpha:1.0];
    lable.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"barbg_friend1_iphone.png"]];
    return lable;
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
 
 */

@end
